import { Injectable, PipeTransform } from '@nestjs/common';
import * as Joi from '@hapi/joi';

@Injectable()
export class UserInfoPipe implements PipeTransform {
  private schema; // 验证规则
  constructor(schema) {
    this.schema = schema;
  }
  transform(value: any) {
    // const { error } = Joi.validate(value, this.schema);
    const { error } = this.schema.validate(value);
    if (error) {
      //   console.log(error);
      return false;
    }
    return value;
  }
}
